package com.gp.activity.main;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.gp.R;
import com.gp.adapter.NavigationPageAdapter;

/**
 * @author shijunxing
 * @className NavigationActivity
 * @date Sep 6, 2013 11:52:59 AM
 * @version 1.0
 * @Description 程序启动导航页
 */
public class NavigationActivity extends Activity {
	
	private ViewPager mViewPager;	
	private ImageView mPage0;
	private ImageView mPage1;
	private ImageView mPage2;
	private ImageView mPage3;
	private ImageView mPage4;
	private ImageView[] Images;
	private  ArrayList<View> views;
	 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_navigationr);
        
        initViewPager();
        initImage();
        mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
        
    }    
    

    private void initImage() {
        
        mPage0 = (ImageView)findViewById(R.id.page0);
        mPage1 = (ImageView)findViewById(R.id.page1);
        mPage2 = (ImageView)findViewById(R.id.page2);
        mPage3 = (ImageView)findViewById(R.id.page3);
        mPage4 = (ImageView)findViewById(R.id.page4);
        Images  = new ImageView[]{mPage0,mPage1,mPage2,mPage3,mPage4,};

    }
    
    private void initViewPager() {
        
          mViewPager = (ViewPager)findViewById(R.id.whatsnew_viewpager);
        //将要分页显示的View装入数组中
          LayoutInflater mLi = LayoutInflater.from(this);
          View view1 = mLi.inflate(R.layout.navigation_a, null);
          View view2 = mLi.inflate(R.layout.navigation_b, null);
          View view3 = mLi.inflate(R.layout.navigation_c, null);
          View view4 = mLi.inflate(R.layout.navigation_d, null);
          View view5 = mLi.inflate(R.layout.navigation_e, null);
          
        //每个页面的view数据
          views = new ArrayList<View>();
          views.add(view1);
          views.add(view2);
          views.add(view3);
          views.add(view4);
          views.add(view5);
          
          mViewPager.setAdapter(new NavigationPageAdapter(views));

    }
    
    
    public class MyOnPageChangeListener implements OnPageChangeListener {
		@Override
		public void onPageSelected(int arg0) {
		 // 循环主要是控制导航中每个小圆点的状态
            for (int i = 0; i < Images.length; i++) {
                // 当前view下设置小圆点为选中状态
                Images[i].setImageDrawable(getResources().getDrawable(
                        R.drawable.page_now));
                // 其余设置为非选中状态
                if (arg0 != i)
                    Images[i].setImageDrawable(getResources().getDrawable(
                            R.drawable.page));
            }
        }

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}
    public void startbutton(View v) {  
      	Intent intent = new Intent();
		intent.setClass(NavigationActivity.this,MainActivity.class);
		startActivity(intent);
		this.finish();
      }  
    
}
